package easybooking.report;

import java.io.Serializable;
import java.util.Vector;

/**
 * This class displays a quantity of several paragraphs
 * (<code>SimpleParagraph</code>-objects). They are hold in a
 *  <code>Vector</code>.
 *
 * @author Hakan Keles
 */
public class CompositeParagraph extends Paragraph implements Serializable {

    /**
     * Storage of the paragraphs.
     */
    private Vector<SimpleParagraph> subParagraphs = new Vector<SimpleParagraph>();

    /**
     * Add a sub paragraph.
     *
     * @param p The added sub paragraph.
     */
    public void addSubParagraph(SimpleParagraph p) {
        this.subParagraphs.addElement(p);
    }

    /**
     * Remove a sub paragraph.
     *
     * @param p The removed sub paragraph.
     */
    public void removeSubParagraph(SimpleParagraph p) {
        this.subParagraphs.removeElement(p);
    }

    /**
     * Read-out all sub paragraphs.
     *
     * @return <code>Vector</code>, which contains the sub paragraphs.
     */
    public Vector<SimpleParagraph> getSubParagraphs() {
        return this.subParagraphs;
    }

    /**
     * Read-out the number of sub paragraphs.
     *
     * @return int Number of sub paragraphs.
     */
    public int getNumParagraphs() {
        return this.subParagraphs.size();
    }

    /**
     * Read-out one sub paragraph.
     *
     * @param i Index of the desired sub paragraph (0 <= i <n),  n =
     * number of sub paragraphs.
     *
     * @return The desired sub paragraph.
     */
    public SimpleParagraph getParagraphAt(int i) {
        return this.subParagraphs.elementAt(i);
    }

    /**
     * Change a <code>CompositeParagraph</code> to a String.
     * @return the paragraph as string
     *
     */
    @Override
    public String toString() {

        StringBuffer result = new StringBuffer();


        for (int i = 0; i < this.subParagraphs.size(); i++) {
            SimpleParagraph p = this.subParagraphs.elementAt(i);


            result.append(p.toString() + "\n");
        }


        return result.toString();
    }
}



